Page({
  onShareAppMessage() {
    return {
      title: '查看通行证',
      path: '/visitor_pkg/pages/passport/index?encryptedData='+this.data.passInfo.encryptedData,
      imageUrl: this.data.passInfo.url,
      isCount:false
    }
  },
  data:{
    passInfo:{},
    isShow:false,
    isCount:false
  },
  onLoad(ev){
    if (ev.id){
      this.setData({
        isShow:true,
        isCount:true
      })
      this.getPassInfo(ev.id)
    }else if(ev.encryptedData){
      this.getFKPassfn(ev.encryptedData)
      this.setData({
        isShow:true,
        isCount:true
      })
    }
   
  },
  // 获取邀请人二维码
  async getPassInfo(id){
    const res = await wx.myRequest.get(`/visitor/${id}`)
    // console.log(res);
    this.setData({
      passInfo:res.data
    })
  },
  // 被邀请人进入页面
  async getFKPassfn(encryptedData){
    const res = await wx.myRequest.get(`/visitor/share/${encryptedData}`)
    this.setData({
      passInfo:res.data
    })
  },
  // 倒计时结束
  countDownfn(){
    this.setData({
      isCount:false
    })
  },
  // 保存到本地
  async savefn(){
    // 获取图片路径
    const res = await wx.getImageInfo({
      src:this.data.passInfo.url
    })
    // console.log(res);
    //保存到本地

    const imgres = await wx.saveImageToPhotosAlbum({
      filePath:res.path
    })

  }
})
